package cn.sciento.starter.social.core.provider;

import java.io.Serializable;
import org.apache.commons.lang3.StringUtils;

public class Provider implements Serializable {
  private static final long serialVersionUID = 2160189747536987135L;
  
  private static final String SPLITTER = "@";
  
  private String providerId;
  
  private String channel;
  
  private String appId;
  
  private String subAppId;
  
  private String appKey;
  
  private String providerName;
  
  private String scope;
  
  private String authorizeUrl;
  
  private String accessTokenUrl;
  
  private String openIdUrl;
  
  private String userInfoUrl;
  
  private String refreshTokenUrl;
  
  public Provider() {}
  
  public Provider(String providerId, String channel, String appId, String appKey, String subAppId) {
    this.providerId = providerId;
    this.channel = channel;
    this.appId = appId;
    this.subAppId = subAppId;
    this.appKey = appKey;
  }
  
  public static String uniqueProviderId(String providerId, String channel) {
    return providerId + "@" + channel;
  }
  
  public static String realProviderId(String providerId) {
    if (!providerId.contains("@"))
      return providerId; 
    String[] arr = StringUtils.split(providerId, "@");
    return arr[0];
  }
  
  public String getProviderId() {
    return this.providerId;
  }
  
  public String getChannel() {
    return this.channel;
  }
  
  public String getAppId() {
    return this.appId;
  }
  
  public String getSubAppId() {
    return this.subAppId;
  }
  
  public void setSubAppId(String subAppId) {
    this.subAppId = subAppId;
  }
  
  public String getAppKey() {
    return this.appKey;
  }
  
  public String getProviderName() {
    return this.providerName;
  }
  
  public Provider setProviderName(String providerName) {
    this.providerName = providerName;
    return this;
  }
  
  public String getScope() {
    return this.scope;
  }
  
  public Provider setScope(String scope) {
    this.scope = scope;
    return this;
  }
  
  public String getAuthorizeUrl() {
    return this.authorizeUrl;
  }
  
  public Provider setAuthorizeUrl(String authorizeUrl) {
    this.authorizeUrl = authorizeUrl;
    return this;
  }
  
  public String getAccessTokenUrl() {
    return this.accessTokenUrl;
  }
  
  public Provider setAccessTokenUrl(String accessTokenUrl) {
    this.accessTokenUrl = accessTokenUrl;
    return this;
  }
  
  public String getOpenIdUrl() {
    return this.openIdUrl;
  }
  
  public void setOpenIdUrl(String openIdUrl) {
    this.openIdUrl = openIdUrl;
  }
  
  public String getUserInfoUrl() {
    return this.userInfoUrl;
  }
  
  public Provider setUserInfoUrl(String userInfoUrl) {
    this.userInfoUrl = userInfoUrl;
    return this;
  }
  
  public String getRefreshTokenUrl() {
    return this.refreshTokenUrl;
  }
  
  public Provider setRefreshTokenUrl(String refreshTokenUrl) {
    this.refreshTokenUrl = refreshTokenUrl;
    return this;
  }
}
